home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Util / CnvConfig / CnvConfig.c next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  6.7 KB  |  294 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     CnvConfig.c
  5.  
  6.     DESCRIPTION
  7.     Converts an old config-file into the actual version or prints an
  8.     old version-file to stdout.
  9.  
  10.     NOTES
  11.  
  12.     BUGS
  13.  
  14.     TODO
  15.  
  16.     EXAMPLES
  17.  
  18.     SEE ALSO
  19.  
  20.     INDEX
  21.  
  22.     HISTORY
  23.     30. Mar 1993    ada created
  24.  
  25. ******************************************************************************/
  26.  
  27. /**************************************
  28.         Includes
  29. **************************************/
  30. #include <exec/types.h>
  31. #include <exec/nodes.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <pragmas/dos_pragmas.h>
  36.  
  37. #ifndef DOS_DOS_H
  38. typedef void * BPTR;
  39. #endif
  40. /* typedef struct Node NODE; */
  41.  
  42. #include "global.h"
  43. #include "config.h"
  44.  
  45.  
  46. /**************************************
  47.         Globale Variable
  48. **************************************/
  49. extern struct DOSBase * DOSBase;
  50.  
  51.  
  52. /**************************************
  53.       Interne Defines & Strukturen
  54. **************************************/
  55.  
  56.  
  57. /**************************************
  58.         Interne Variable
  59. **************************************/
  60.  
  61.  
  62. /**************************************
  63.        Interne Prototypes
  64. **************************************/
  65. void convert_config0001 (void);
  66. void print_config (void);
  67.  
  68.  
  69. struct Config new;
  70. struct Config0001 c1;
  71. struct Config0002 c2;
  72.  
  73.  
  74. void convert_config0001 (void)
  75. {
  76.     new.wwcol = c1.wwcol;
  77.     new.winx = c1.winx;
  78.     new.winy = c1.winy;
  79.     new.winwidth = c1.winwidth;
  80.     new.winheight = c1.winheight;
  81.     new.iwinx = c1.iwinx;
  82.     new.iwiny = c1.iwiny;
  83.     new.aslleft = c1.aslleft;
  84.     new.asltop = c1.asltop;
  85.     new.aslwidth = c1.aslwidth;
  86.     new.aslheight = c1.aslheight;
  87.     new.tabstop = c1.tabstop;
  88.     new.margin = c1.margin;
  89.     new.fgpen = c1.fgpen;
  90.     new.bgpen = c1.bgpen;
  91.     new.hgpen = c1.hgpen;
  92.     new.tpen = c1.tpen;
  93.     new.bbpen = c1.bbpen;
  94.     new.insertmode = c1.insertmode;
  95.     new.ignorecase = c1.ignorecase;
  96.     new.wordwrap = c1.wordwrap;
  97.     new.autosplit = c1.autosplit;
  98.     new.autoindent = c1.autoindent;
  99.     new.autounblock = c1.autounblock;
  100. } /* convert_config0001 */
  101.  
  102.  
  103. void convert_config0002 (void)
  104. {
  105.     new.wwcol = c2.wwcol;
  106.     new.winx = c2.winx;
  107.     new.winy = c2.winy;
  108.     new.winwidth = c2.winwidth;
  109.     new.winheight = c2.winheight;
  110.     new.iwinx = c2.iwinx;
  111.     new.iwiny = c2.iwiny;
  112.     new.aslleft = c2.aslleft;
  113.     new.asltop = c2.asltop;
  114.     new.aslwidth = c2.aslwidth;
  115.     new.aslheight = c2.aslheight;
  116.     new.tabstop = c2.tabstop;
  117.     new.margin = c2.margin;
  118.     new.fgpen = c2.fgpen;
  119.     new.bgpen = c2.bgpen;
  120.     new.hgpen = c2.hgpen;
  121.     new.tpen = c2.tpen;
  122.     new.bbpen = c2.bbpen;
  123.     new.insertmode = c2.insertmode;
  124.     new.ignorecase = c2.ignorecase;
  125.     new.wordwrap = c2.wordwrap;
  126.     new.autosplit = c2.autosplit;
  127.     new.autoindent = c2.autoindent;
  128.     new.autounblock = c2.autounblock;
  129. } /* convert_config0002 */
  130.  
  131.  
  132. void print_config (void)
  133. {
  134.     printf ("wwcol %d\n", new.wwcol);
  135.     printf ("setgeometry %d %d %d %d\n",
  136.         new.winx, new.winy, new.winwidth, new.winheight);
  137.     printf ("# iconpos %d %d\n", new.iwinx, new.iwiny);
  138.     printf ("# aslgeometry %d %d %d %d\n",
  139.         new.aslleft, new.asltop, new.aslwidth, new.aslheight);
  140.     printf ("tabstop %d\n", new.tabstop);
  141.     printf ("margin %d\n", new.margin);
  142.     printf ("fgpen %d\n", new.fgpen);
  143.     printf ("bgpen %d\n", new.bgpen);
  144.     printf ("hgpen %d\n", new.hgpen);
  145.     printf ("tpen %d\n", new.tpen);
  146.     printf ("bbpen %d\n", new.bbpen);
  147.  
  148.     printf ("insertmode %s\n", new.insertmode ? "on" : "off");
  149.     printf ("ignorecase %s\n", new.ignorecase ? "on" : "off");
  150.     printf ("wordwrap %s\n", new.wordwrap ? "on" : "off");
  151.     printf ("autosplit %s\n", new.autosplit ? "on" : "off");
  152.     printf ("autoindent %s\n", new.autoindent ? "on" : "off");
  153.     printf ("autounblock %s\n", new.autounblock ? "on" : "off");
  154. } /* print_config */
  155.  
  156.  
  157. void main (int argc, char ** argv)
  158. {
  159.     FILE * fh;
  160.     char tmp_buffer[256];
  161.     int out = 0;
  162.     char * outfile = XDME_CONFIG;
  163.     int current;
  164.  
  165.     if (argc == 2 && argv[1][0] == '?')
  166.     {
  167. usage:
  168.     puts ("CnvConfig converts old config-files\n"
  169.           "Usage : CnvConfig [-p] [-o <file>]\n\n"
  170.           "Without arguments it asks whether to write the new config\n"
  171.           "back or prints it on stdout.\n"
  172.           "You can specify either -p or -o. -p prints the old config\n"
  173.           "to stdout. You can redirect this into a file and let XDME\n"
  174.           "source this file. Or -o <file> writes the new config to\n"
  175.           "<file>.");
  176.     exit (0);
  177.     }
  178.     else if (argc > 1 && argv[1][0] == '-')
  179.     {
  180.     if (argv[1][1] == 'p')
  181.         out = 2;
  182.     else if (argv[1][1] == 'o')
  183.     {
  184.         if (argv[1][2])
  185.         outfile = &argv[1][2];
  186.         else
  187.         {
  188.         if (argc != 3)
  189.             goto usage;
  190.  
  191.         outfile = argv[2];
  192.         }
  193.  
  194.         out = 1;
  195.     }
  196.     else
  197.         goto usage;
  198.     }
  199.  
  200.     if (fh = fopen (XDME_CONFIG, "r"))
  201.     {
  202.     fread (tmp_buffer, sizeof(CONFIG_VERSION)-1, 1, fh);
  203.  
  204.     if (!strncmp (CONFIG0001, tmp_buffer, sizeof(CONFIG0001)-1) )
  205.     {
  206.         printf ("# Found config \"" CONFIG0001 "\" ...\n");
  207.  
  208.         fgetc (fh);
  209.         fread (&c1, 1, CONFIG0001_SIZE, fh);
  210.  
  211.         convert_config0001 ();
  212.     }
  213.     else if (!strncmp (CONFIG0002, tmp_buffer, sizeof(CONFIG0002)-1) )
  214.     {
  215.         printf ("# Found config \"" CONFIG0002 "\" ...\n");
  216.  
  217.         fgetc (fh);
  218.         fread (&c2, 1, CONFIG0002_SIZE, fh);
  219.  
  220.         convert_config0002 ();
  221.     }
  222.     else if (!strncmp (CONFIG_VERSION, tmp_buffer, sizeof(CONFIG0003)-1) )
  223.     {
  224.         current = TRUE;
  225.  
  226.         printf ("# Found current config ...\n");
  227.  
  228.         fread (&new, 1, CONFIG_SIZE, fh);
  229.     }
  230.     else
  231.     {
  232.         tmp_buffer[sizeof(CONFIG_VERSION)] = 0;
  233.  
  234.         printf ("Unknown config-file \"%s\"\n", tmp_buffer);
  235.         exit (5);
  236.     }
  237.  
  238.     fclose (fh);
  239.  
  240.     if (!out)
  241.     {
  242.         printf ("Do you want\n%s"
  243.         "\t(2) print config to stdout\n"
  244.         "\t(3) exit without doing anything\n"
  245.         ":",
  246.         current ? "" : "\t(1) convert \"" XDME_CONFIG "\" to \"" CONFIG_VERSION "\" \n"
  247.         );
  248.  
  249.         gets (tmp_buffer);
  250.         out = atoi (tmp_buffer);
  251.     }
  252.  
  253.     switch (out)
  254.     {
  255.     case 1:
  256.         printf ("Copying \"" XDME_CONFIG "\" to \"" XDME_CONFIG ".bak\"\n");
  257.         DeleteFile (XDME_CONFIG ".bak");
  258.         Rename (XDME_CONFIG, XDME_CONFIG ".bak");
  259.  
  260.         if (fh = fopen (outfile, "w"))
  261.         {
  262.         printf ("Writing new config-file.\n");
  263.         fwrite (CONFIG_VERSION, sizeof(CONFIG_VERSION)-1, 1, fh);
  264.         fwrite (&new, CONFIG_SIZE, 1, fh);
  265.         fclose (fh);
  266.         }
  267.         else
  268.         {
  269.         printf ("Cannot open \"%s\" for writing.\n"
  270.             "copying \"" XDME_CONFIG ".bak\" back\n" , outfile);
  271.         Rename (XDME_CONFIG ".bak", XDME_CONFIG);
  272.         exit (10);
  273.         }
  274.  
  275.         break;
  276.  
  277.     case 2:
  278.         print_config ();
  279.     }
  280.     }
  281.     else
  282.     {
  283.     printf ("Cannot open \"" XDME_CONFIG "\" for reading.\n");
  284.     exit (10);
  285.     }
  286.  
  287.     exit (0);
  288. }
  289.  
  290.  
  291. /******************************************************************************
  292. *****  ENDE CnvConfig.c
  293. ******************************************************************************/
  294.